package com.zmn.plat.admin.controller.service.itemdetail;

import com.zmn.common.utils.number.NumberUtil;
import com.zmn.plat.model.entity.service.itemdetail.ItemDetail;
import com.zmn.plat.model.entity.service.itemdetail.ItemDetailQuery;
import com.zmn.plat.services.interfaces.service.itemdetail.ItemDetailService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;


/**
 * 项目明细-计价器3.0基础查询Controller
 *
 * @author guoqiao
 * @since 2021/11/19 15:02
 */
@Slf4j
@RestController
@RequestMapping("/service/itemdetail")
public class ItemDetailListController extends ServiceItemDetailBaseController{

    private ItemDetailService itemDetailService;

    /**
     * 描述: 查询列表
     *
     * @author guoqiao
     * @since 2021/11/19 15:02
     */
    @RequestMapping("/list")
    public ModelAndView list(ItemDetailQuery query) {

        List<ItemDetail> items = itemDetailService.listPageByQuery(query);

        ModelAndView mv = new ModelAndView("service/itemdetail/list");
        mv.addObject("items", items);
        mv.addObject("vo", query);

        return mv;
    }

    /**
     * 描述: 详情
     *
     * @author guoqiao
     * @since 2021/11/19 15:02
     */
    @RequestMapping("/addEditView")
    public ModelAndView addEditView(@RequestParam(value = "itemId") Integer itemId) {

        ItemDetail itemDetail;
        if (NumberUtil.isNullOrZero(itemId)) {
            itemDetail = new ItemDetail();
        } else {
            itemDetail =  itemDetailService.findById(itemId);
        }
        ModelAndView mv = new ModelAndView("service/itemdetail/detail");
        mv.addObject("itemDetail", itemDetail);

        return mv;
    }

}
